﻿package net.cooltain.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@SuppressWarnings("unchecked")
public class CollectionUtils {
	
	/**
	 * 判断一个集合为空
	 * @param collection
	 * @return
	 */
	public static boolean isEmpty(Collection collection){
		if(collection!=null && collection.size()>0){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * 判断一个集合不为空
	 * @param collection
	 * @return
	 */
	public static boolean notEmpty(Collection collection){
		if(collection!=null && collection.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 将一个集合随机排序
	 * @param collection
	 * @return
	 */
	public static List randomSort(List list){
		if(CollectionUtils.notEmpty(list)){
			List listTemp = list;
			list = new ArrayList();
			while(listTemp.size()>0){
				int randIndex = (int) (Math.random()*listTemp.size());
				Object randObj = listTemp.get(randIndex);
				list.add(randObj);
				listTemp.remove(randIndex);
			}
		}
		return list;
	}
	
}
